package com.zrrd.common.config;

import com.zrrd.common.properties.MinIOConfigProperties;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author WanJl
 * @version 1.0
 * @title MinIOConfig
 * @description MinIO的核心配置类
 * @create 2024/9/12
 */
@Data
@Configuration  //将当前类设置为springboot核心配置类之一
@EnableConfigurationProperties({MinIOConfigProperties.class})
//当某个接口被使用的时候才会加载该配置
public class MinIOConfig {

    @Resource
    private MinIOConfigProperties minIOConfigProperties;

    @Bean
    public MinioClient getMinioClient() {
        return MinioClient
                .builder()
                .credentials(minIOConfigProperties.getAccessKey(),
                        getMinIOConfigProperties().getSecretKey())
                .endpoint(minIOConfigProperties.getEndpoint())
                .build();
    }

}
